<?php


namespace app\common\model;


use think\Db;
use think\Model;

class Base extends Model
{

    protected $_time;
    protected $_primaryKey;
    protected $table;
    protected $_zoneName;

    // 重构函数
    public function __construct($data = [])
    {
        parent::__construct($data);
    }

    /**
     * 写入错误信息
     * @param int $code
     * @param string $msg
     */
    protected function setError($code=0, $msg='') {
        $this->error["code"] = $code;
        $this->error["msg"] = $msg;
    }
    /**
     * 获取错误信息
     * @param string $type
     */
    public function getError($type="msg") {
        return $this->error[$type];
    }

    /**
     * @param array $where  // 查询的条件
     * @param string $item  // 查询的参数
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function getOne($where=[1], $item='*')
    {
        $rs = Db::table($this->table)
            ->field($item)
            ->where($where)
            ->find();

        return $rs;
    }

    /**
     * @param mixed $where  // 更新的条件
     * @param $data         // 更新的数据
     * @return bool|int|string
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    function getUpdate($where, $data)
    {
        $rs = Db::table($this->table)
            ->where($where)
            ->data($data)
            ->update();
        return $rs;
    }
}